/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.guide.web;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.web.Result;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.guide.entity.*;
import com.jeeplus.modules.guide.service.MobileEvaluateService;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 事项评价Controller
 * @author azj
 * @version 2021-5-15
 */
@RestController
@RequestMapping("/mobileEvaluate")
@RequiredArgsConstructor
public class MobileEvaluateController extends BaseController {
	private final MobileEvaluateService mobileEvaluateService;

	/**
	 * getEvaluateTree 获取事项评价满意度
	 *
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="getEvaluateTree")
	public AjaxJson getEvaluateTree() {
		return AjaxJson.success("加载成功！").put("data", mobileEvaluateService.getEvaluateTree());
	}

	/**
	 * getEvaluateValue 获取评价主题
	 *
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="getEvaluateValue")
	@RequiresPermissions("mobileEvaluate:view")
	public AjaxJson getEvaluateValue(String id) {
		return AjaxJson.success("操作成功！").put("data", mobileEvaluateService.getEvaluateValue(id));
	}

	/**
	 * getEvaluateValueHistory 获取评价
	 * id评价id
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="getEvaluateValueHistory")
	@RequiresPermissions("mobileEvaluate:view")
	public AjaxJson getEvaluateValueHistory(String id) {
		return AjaxJson.success("操作成功！").put("data", mobileEvaluateService.getEvaluateValueHistory(id));
	}



	/**
	 * delEvaluate 删除评价主题
	 * id主题id
	 * @author azj
	 * @version 2020-04-24
	 */
	@RequiresPermissions("mobileEvaluate:del")
	@GetMapping(value ="delEvaluate")
	public AjaxJson delEvaluate(String id) {
		mobileEvaluateService.delEvaluate(id);
		return AjaxJson.success("操作成功！");
	}


	/**
	 * updateEvaluate 更新评价主题
	 * MobileEvaluate评价实体
	 * @author azj
	 * @version 2020-04-24
	 */
	@RequiresPermissions("mobileEvaluate:edit")
	@PostMapping(value ="updateEvaluate")
	public AjaxJson updateEvaluate(MobileEvaluate me) {
		mobileEvaluateService.updateEvaluate(me);
		return AjaxJson.success("操作成功！");
	}

	/**
	 * updateEvaluateHistory 更新评价
	 * 评价id
	 * 审核状态doStatus
	 * @author azj
	 * @version 2020-04-24
	 */
	@RequiresPermissions("mobileEvaluate:edit")
	@PostMapping(value ="updateEvaluateHistory")
	public AjaxJson updateEvaluateHistory(String id,int doStatus) {
		mobileEvaluateService.updateEvaluateHistory(id,doStatus);
		return AjaxJson.success("操作成功！");
	}



	/**
	 * getEvaluateValue 获取事项评价满意度
	 *
	 * @author azj
	 * @version 2020-04-24
	 */
	@RequiresPermissions("mobileEvaluate:add")
	@PostMapping(value ="insertEvaluate")
	public AjaxJson insertEvaluate(MobileEvaluate me) {
		mobileEvaluateService.insertEvaluate(me);
		return AjaxJson.success("操作成功！");
	}

	/**
	 * getMatterLabelList 获取pc评价分类集合
	 * evaluateLevel评价满意度
	 * @author azj
	 * @version 2020-04-24
	 */
	@RequiresPermissions("mobileEvaluate:list")
	@GetMapping(value ="getMobileEvaluateList")
	public AjaxJson getMobileEvaluateList(String evaluateLevel,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<>();
		map.put("curPage",pageNo);
		map.put("pageSize",pageSize);
		map.put("evaluateLevel",evaluateLevel);
		return AjaxJson.success("加载成功！").put("data", mobileEvaluateService.getMobileEvaluateList(map));
	}

	/**
	 * userListEvaluate 获取群众评价集合
	 * oid 事项id/一页一证id
	 * isThing是否一页一证 1是0否
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="userListEvaluate")
	public Result<List<MobileUserListEvaluate>> userListEvaluate(@RequestParam("oid")String oid, @RequestParam("isThing") int isThing, int pageNo, int pageSize) {
		Map<String,Object> map = new HashMap<>();
		map.put("curPage",pageNo);
		map.put("pageSize",pageSize);
		map.put("oid",oid);
		map.put("isThing",isThing);
		return Result.succeed(mobileEvaluateService.userListEvaluate(map).getDatas(), "获取成功");
	}


	/**
	 * userCountEvaluate 获取群众总评价率统计
	 * oid 事项id/一页一证id
	 * isThing是否一页一证 1是0否
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="userCountEvaluate")
	public AjaxJson userCountEvaluate( @RequestParam("oid")String oid, @RequestParam("isThing") int isThing) {
		List<MobileCountEvaluate> me = mobileEvaluateService.userCountEvaluate(oid,isThing);
		List<MobileCountLevel> ml = mobileEvaluateService.userCountByLevel(oid,isThing);
		for(MobileCountEvaluate mes : me){
			mes.setEvaluateList(new ArrayList<MobileCountLevel>());
			for(MobileCountLevel mls : ml){
				if(mes.getEvaluateLevel().equalsIgnoreCase(mls.getEvaluateLevel())){
					mes.getEvaluateList().add(mls);
				}
			}
		}
		return AjaxJson.success("加载成功！").put("appraiseCount", me);
	}

	/**
	 * findEvaluateList 获取群众评价集合
	 * evaluateLevel评价满意度
	 * @author azj
	 * @version 2020-04-24
	 */
	@RequiresPermissions("mobileEvaluate:list")
	@GetMapping(value ="findEvaluateList")
	public AjaxJson findEvaluateList(String evaluateLevel,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<>();
		map.put("curPage",pageNo);
		map.put("pageSize",pageSize);
		map.put("evaluateLevel",evaluateLevel);
		return AjaxJson.success("加载成功！").put("data", mobileEvaluateService.findEvaluateList(map));
	}


	/**
	 * getEvaluateList 获取手机端评价分类集合
	 *
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="getEvaluateList")
	public Result<List<MobileEvaluateValue>> getEvaluateList() {
		List<MobileEvaluateValue> list =  mobileEvaluateService.getEvaluateTree();
		List<MobileEvaluate> meList = mobileEvaluateService.getEvaluateList();
		for(MobileEvaluateValue me :list){
			me.setEvaluateList(new ArrayList<MobileEvaluate>());
			for(MobileEvaluate ev : meList){
				if(ev.getEvaluateLevel().equals(me.getEvaluateLevel())){
					me.getEvaluateList().add(ev);
				}
			}
		}
		return Result.succeed(list, "获取成功");
	}

	/**
	 * getEvaluateValue 添加评价
	 * MobileEvaluateHistory评价实体类
	 * @author azj
	 * @version 2020-04-24
	 */
	@PostMapping(value ="insertEvaluateValue")
	public AjaxJson insertEvaluateValue(@RequestBody MobileEvaluateHistory me) {
		mobileEvaluateService.insertEvaluateValue(me);
		return AjaxJson.success("操作成功！");
	}
}
